home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: 71024.1713@compuserve.com
- Newsgroups: comp.lang.c++
- Subject: Re: OWL: Palette problem - Please HELP!
- Date: Wed, 31 Jan 1996 22:31:09 GMT
- Organization: CompuServe Incorporated
- Message-ID: <4eoqj4$r83@dub-news-svc-5.compuserve.com>
- References: <4elus8$e5m@bigboote.WPI.EDU>
- NNTP-Posting-Host: hd83-002.compuserve.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- kevint@wpi.edu (Kevin Theroux) wrote:
-
-
-
- >Hi there,
- >I hope someone out there can help...I'm really stuck and in a time cruch.
-
- >I am taking a course in Graphics and decided to use the PC for my projects.
- >I just need to get a bare-bones app going so I can do my project. I want
- >to create a simple window, create a bitmap in the window (so I can draw
- >to it), create a palette (aka color map) and get access to the palette to
- >change colors.
-
- >I have everything working EXCEPT creating and modifying a palette.
- >Can someome PLEASE help me out with this. My code is below.
- >If you already have a skeleton app that does what I'm looking for,
- >could you please email it to me or tell me what I did wrong?
- >(kevint@cs.wpi.edu)
-
- >The code I have for creating a palette came directly from a Borland
- >example...but it doesn't work. I'm using Borland C++ v4.5.
-
- >Thank you,
-
-
- Hey Kevin,
-
- First of all I couldn't find CreatePalette in the Owl library but I
- did find it in the windows API. If you desire to use the Windows API,
- the call should include double colons, ( ::CreatePalette).
-
- Also in the example directory ( examples\owl\owlapi\palette) you can
- find a good example that will probably answer most of your questions.
-
- Lastly, I wouldn't do all the Palette stuff in setupwindow. I would
- do it in EvPaint or another event method (see example).
-
- Hope this helps..
-
- John
- >Kevin Theroux :-)
-
- >============================================================================
-
- >#include <owl/owlpch.h>
- >#include <owl/applicat.h>
- >#include <owl/framewin.h>
- >#include <owl/dc.h>
- >#include <owl/inputdia.h>
- >#include <owl/color.h>
- >#include <stdlib.h>
-
- >/*------------------------------------------------------------------------*/
-
- >#define NUM_PALETTE_ENTRIES 128
-
- >/*------------------------------------------------------------------------*/
-
- >int width, height;
- >HPALETTE hpal;
- >PALETTEENTRY ape[NUM_PALETTE_ENTRIES];
- >LOGPALETTE* plgpl;
-
- >/*------------------------------------------------------------------------*/
-
- >class myWindow : public TWindow
- >{
- > TMemoryDC *myMemoryBitmap; // this is where to draw to, then it is
- > // BitBlt'ed to the window
-
- > public:
- > myWindow(TWindow* parent = 0);
- > void SetupWindow();
- > ~myWindow()
- > {
- > }
-
- > protected:
- > // Message response functions
-
- > void Paint(TDC& dc, BOOL erase, TRect& rect);
- >};
-
- >/*------------------------------------------------------------------------*/
-
- >myWindow::myWindow(TWindow* parent)
- >{
- > Init(parent, 0, 0);
- >}
-
- >/*------------------------------------------------------------------------*/
-
- >void
- >myWindow::Paint(TDC& dc, BOOL, TRect& )
- >{
- > dc.BitBlt( GetClientRect(), *myMemoryBitmap, TPoint(0,0));
- >}
-
- >/*------------------------------------------------------------------------*/
-
- >void
- >myWindow::SetupWindow()
- >{
- > int i, j, k, red, green, blue;
-
- > TWindow::SetupWindow();
-
- > myMemoryBitmap = new TMemoryDC( TClientDC (HWindow));
- > myMemoryBitmap->SelectObject (TBitmap (width, height, 1, 32));
-
- > plgpl = (LOGPALETTE*) LocalAlloc (LPTR,
- > sizeof(LOGPALETTE) + NUM_PALETTE_ENTRIES * sizeof(PALETTEENTRY));
-
- > plgpl->palNumEntries = NUM_PALETTE_ENTRIES;
- > plgpl->palVersion = 0x300;
-
- > for (i = 0, red = 0, green = 127, blue = 127; i < NUM_PALETTE_ENTRIES;
- > i++, red += 1, green += 1, blue += 1)
- > {
- > ape[i].peRed = plgpl->palPalEntry[i].peRed = LOBYTE(red);
- > ape[i].peGreen = plgpl->palPalEntry[i].peGreen = LOBYTE(green);
- > ape[i].peBlue = plgpl->palPalEntry[i].peBlue = LOBYTE(blue);
- > ape[i].peFlags = plgpl->palPalEntry[i].peFlags = PC_RESERVED;
- > }
-
- > hpal = CreatePalette(plgpl); // * * THIS ALWAYS RETURNS NULL * *
-
- > AnimatePalette(hpal, 0, NUM_PALETTE_ENTRIES,
- > (PALETTEENTRY FAR*) &ape);
- >}
-
- >/*------------------------------------------------------------------------*/
-
- >class myApp : public TApplication {
- > public:
- > myApp() : TApplication() {}
-
- > void InitMainWindow()
- > {
- > TFrameWindow *my_FrameWindow = \
- > new TFrameWindow(0, "Draw", new myWindow(0), true);
- >
- > width = TScreenDC().GetDeviceCaps( HORZRES );
- > height = TScreenDC().GetDeviceCaps( VERTRES );
-
- > my_FrameWindow->Attr.X = (width -600)/2;
- > my_FrameWindow->Attr.Y = (height-400)/2-20;
-
- > SetMainWindow (my_FrameWindow);
- > }
- >};
-
- >/*------------------------------------------------------------------------*/
-
- >int
- >OwlMain(int /*argc*/, char* /*argv*/ [])
- >{
- > return myApp().Run();
- >}
-
- >/*------------------------------------------------------------------------*/
-
-
-